﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using  System.Runtime.InteropServices;
using Microsoft.Win32;




namespace MyScreenSaver
{
    

    public partial class ScreenSaverForm : Form
    {
        
        public ScreenSaverForm()
        {
            InitializeComponent();
        }
        List<Word> MyDictionary;
        int TimerInterval; 
        public ScreenSaverForm(Rectangle Bounds, List<Word> Dictionary, int TimerInt)
        {
            InitializeComponent();
            this.Bounds = Bounds;
            MyDictionary = Dictionary;
            TimerInterval = TimerInt;

        }

        

        private void ScreenSaverForm_Load(object sender, EventArgs e)
        {
            
            textLabel.Text = "";
            Cursor.Hide();
            TopMost = true;
            moveTimer.Interval = TimerInterval;
            moveTimer.Tick += new EventHandler(moveTimer_Tick);
            moveTimer.Start();
        }
        private Random rand = new Random();
        private void moveTimer_Tick(object sender, System.EventArgs e)
        {
                        
            int count = MyDictionary.Count;
            int number = rand.Next(count); //'это номер от 0 до кол-ва записей в словаре. нужно перекинуть словарь сюда
            textLabel.Text=MyDictionary[number].EnglishWord+" " +MyDictionary[number].RussionWord+" "+MyDictionary[number].Description;
            textLabel.Left = rand.Next(Math.Max(1, Bounds.Width - textLabel.Width));
            textLabel.Top = rand.Next(Math.Max(1, Bounds.Height - textLabel.Height));
        }

        private Point mouseLocation;
        private void ScreenSaverForm_MouseMove(object sender, MouseEventArgs e)
        {
             if (!mouseLocation.IsEmpty)
                 if (Math.Abs(e.X - mouseLocation.X) > 5 || Math.Abs(e.Y - mouseLocation.Y) > 5)
                       Application.Exit();
            mouseLocation = e.Location;
        }

        private void ScreenSaverForm_MouseClick(object sender, MouseEventArgs e)
        {
             Application.Exit();
        }

        private void ScreenSaverForm_KeyPress(object sender, KeyPressEventArgs e)
        {
             Application.Exit();
        }
    }
}
